/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) PathKt.java 2018-08-05 22:10
 */

package cn.jh.common.core.io;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Predicate;
import java.util.regex.Pattern;


/**
 * @author Fuchun
 * @since 1.0
 */
public class PathKt {

    private static final Predicate<String> WIN_PATH = Pattern.compile("^/?[C-Z]:/").asPredicate();

    public static Path resourcePath(String resPath) {
        String classes = PathKt.class.getResource("/").getPath();
        if (WIN_PATH.test(classes)) {
            classes = classes.substring(1);
        }
        Path classesPath = Paths.get(classes);
        Path resourcesPath = classesPath.getParent().getParent();
        return resourcesPath.resolve("src/main/resources" + resPath);
    }

    /** 编译目标目录。*/
    public static Path targetPath() {
        return resourcePath("/").getParent();
    }

    private PathKt() {}
}
